package com.forestar.mapControl.utils.mapConvert.geometry;

import com.forestar.mapControl.utils.mapConvert.geometry.coordinatesystem.CoordinateSystem;
import com.forestar.mapControl.utils.mapConvert.geometry.coordinatesystem.ZoneType;
import com.forestar.mapControl.utils.mapConvert.geometry.utils.GeometryUtils;
import com.mapzone.api.geometry.mzMultiLineString;
import com.mapzone.api.geometry.mzPath;

public class GeoMultiLine implements IGeometry
  {

    private CoordinateSystem coordSystem;

    private mzMultiLineString internalmzMultiLineString;

    private int[] linesPointsCount;
    private double[][] points;

    public GeoMultiLine(CoordinateSystem coordSystem)
      {
        this.coordSystem = coordSystem;
        this.internalmzMultiLineString = new mzMultiLineString();
        int nSrid = coordSystem.getSrid();
        this.internalmzMultiLineString.setSrid(nSrid);
      }

    public GeoMultiLine(CoordinateSystem coordSystem, mzMultiLineString multiLineString)
      {
        this.coordSystem = coordSystem;
        this.internalmzMultiLineString = multiLineString;
      }

    @Override
    public GeometryType getGeometryType()
      {
        return GeometryType.GeometryTypeMultiPolyline;
      }

    @Override
    public CoordinateSystem getCoordinateSystem()
      {
        return coordSystem;
      }

    @Override
    public Envelope getEnvelope()
      {
        return GeometryUtils.getEnvelope(internalmzMultiLineString);
      }

    @Override
    public void setCoordinateSystem(CoordinateSystem coordSystem)
      {
        this.coordSystem = coordSystem;
      }

    public GeoLine getGeoLine(int nIndex)
      {
        mzPath path = internalmzMultiLineString.GetPath(nIndex);
        return new GeoLine(this.coordSystem, path);
      }

    public int getGeoLineCount()
      {
        return internalmzMultiLineString.getPathCount();
      }

    @Override
    public IGeometry Clone()
      {
        mzMultiLineString m_mzMultiLineStringClone = (mzMultiLineString) this.internalmzMultiLineString.clone();
        return new GeoMultiLine(this.coordSystem, m_mzMultiLineStringClone);
      }

    @Override
    public byte[] getBlob()
      {
        return GeoConverter.Geom2Blob(this.internalmzMultiLineString);
      }

    @Override
    public Object getInternalObject()
      {
        return internalmzMultiLineString;
      }

    @Override
    public boolean isSimple()
      {
        return internalmzMultiLineString.IsSimple();
      }

    //获取长度
    public double getLength()
      {
        return internalmzMultiLineString.getLength();
      }

    //长度,获取几何的真实长度，跨带线先分割，再投影到各自SRID下，再求长度和
    public double getLengthEx(ZoneType zoneType)
      {
        return internalmzMultiLineString.getLengthEx(zoneType.getValue());
      }
  }
